package com.design_pattern._02_structure._02_composite;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

public class Composite {
    public static void main(String[] args) throws IOException {
        String dir = System.getProperty("user.dir");
        System.out.println("dir = " + dir);

        String path = new File(".").getCanonicalPath();
        System.out.println("path = " + path);

        print(Arrays.asList(new File(path)), "");
    }

    private static void print(List<File> fileList, String prefix){
        if (fileList == null || fileList.isEmpty()){
            return;
        }
        for (File file : fileList) {
            if (file.exists()){
                String name = file.getName();
                System.out.println(prefix+name);
            }
            if (file.isDirectory()){
                print(Arrays.asList(file.listFiles()), prefix+"  ");
            }
        }
    }
}
